#include "CycleQueue.hpp"
#include <pthread.h>
#include <unistd.h>
#include <ctime>

void* Consumer(void* args)
{
    CycleQueue<int>* cq = static_cast<CycleQueue<int>*>(args);
    while (true)
    {
        int data = 0;
        cq->Pop(&data);
        std::cout << "Consumer->" << data << std::endl;
    }
}
void* Productor(void* args)
{
    CycleQueue<int>* cq = static_cast<CycleQueue<int>*>(args);
     while (true)
    {
        int data = rand() % 10 + 1;
        cq->Push(data);
        std::cout << "Productor->" << data << std::endl;
    }
    
}

int main()
{
    srand(time(nullptr));
    CycleQueue<int>* cq = new CycleQueue<int>();
    pthread_t c1, c2, p1, p2, p3;
    pthread_create(&c1, nullptr, Consumer, cq);
    pthread_create(&c2, nullptr, Consumer, cq);
    pthread_create(&p1, nullptr, Productor, cq);
    pthread_create(&p2, nullptr, Productor, cq);
    pthread_create(&p3, nullptr, Productor, cq);

    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(p1, nullptr);
    pthread_join(p2, nullptr);
    pthread_join(p3, nullptr);
    return 0;
}
// int main()
// {
//    //单生产单消费
//     srand(time(nullptr));
//     CycleQueue<int>* cq = new CycleQueue<int>();
//     pthread_t c, p;
//     pthread_create(&c, nullptr, Consumer, cq);
//     pthread_create(&p, nullptr, Productor, cq);

//     pthread_join(c, nullptr);
//     pthread_join(p, nullptr);
//     return 0;
// }

